define(function(require, exports, module) {

	var $ = require('jquery');
	require('jbox');
	require('../util/tinymce-admin-page.js');	
	require('jquery/jquery-form/1.0.0/jquery.form.js');
	require('jquery/jquery-file-upload/8.8.5/vendor/jquery.ui.widget.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.iframe-transport.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.fileupload.js');

	var info = '';

	//加载
	var url = $CONFIG.base_url + '/api/configure/get';
	$.get(url,function(data){
		info = data;
		$("#img-preview").append('<img src="' + $CONFIG.base_url + 
			'/common/attachment/download/' + info.loginId + '/125x125"/>')
		//加载联系信息
		$("#username").val(info.username);
		$("#phone").val(info.phone);
		$("#mail").val(info.mail);
		$("#qq").val(info.qq);
		$("#address").val(info.address);
	});

	


	//加载关于我们
	tinymce.init({
			selector : 'textarea#aboutus',
			theme : "modern",
			plugins : [ "preview image table contextmenu",
			            "emoticons paste textcolor"],
			            toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
			            toolbar2: "print preview media | forecolor backcolor emoticons",
			language : 'zh_CN',
			height:'200px',
			file_browser_callback : function(field_name, url, type, win) {
				if (type == 'image') {
					$('#fileupload').click();
				}
			},
			init_instance_callback:load_aboutus,
		});
	function load_aboutus(inst){
		$("#aboutus_ifr").contents().find("#tinymce").html(info.aboutUs);
	}

	//更新
	$("#save1").click(function(){
		var aboutus = tinyMCE.get('aboutus').getContent();
		console.log(aboutus);
		$.ajax({
			url: $CONFIG.base_url + '/api/configure/update',
			type:'POST',
			data:{'aboutUs':aboutus},
			success : function(data) {
					if(data)
					$.jBox.tip('更新成功~');
				else
					$.jBox.tip('更新失败~');
			},
			error : function() {
				$.jBox.tip('亲~出问题啦，请再试一次！');
			}
		})

	})

	$("#save2").click(function(){
		$.ajax({
			url: $CONFIG.base_url + '/api/configure/update',
			type:'POST',
			data:{  'username':$("#username").val(),
					'phone':$("#phone").val(),
					'mail':$("#mail").val(),
					'qq':$("#qq").val(),
					'address':$("#address").val()
			},
			success : function(data) {
					if(data)
					$.jBox.tip('更新成功~');
				else
					$.jBox.tip('更新失败~');
			},
			error : function() {
				$.jBox.tip('亲~出问题啦，请再试一次！');
			}
		})

	})
});